const cloud = require('wx-server-sdk')
cloud.init({
  traceUser: true,
  env: "test-7gxzn7uuc171e9e9"
})
const db = cloud.database()
exports.main = async(event, context) => {
  let {
    type,
    _id
  } = event
  try {
    if (type == 'all') {
      const _ = db.command
      return await db.collection('order').where({
       _id: _.exists(true) //只要id字段存在，就删除
      }).remove()
    } else {
      return await db.collection('order').where({
        _id: _id
      }).remove()
    }

  } catch (e) {
    console.error(e)
  }
}